package com.tuanzi.loan.workflow.service.impl;

import org.activiti.engine.RepositoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Lists;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.workflow.repository.HistoryTaskRepository;
import com.tuanzi.loan.workflow.repository.RunningTaskRepository;
import com.tuanzi.loan.workflow.service.WorkflowTaskService;
import com.tuanzi.loan.workflow.vo.ProcessDefinitionResponse;
import com.tuanzi.loan.workflow.vo.TaskSearchRequest;
import com.tuanzi.loan.workflow.vo.TaskSearchResponse;

/**
 * @author Ray
 * @date 2018/01/16
 */
@Service
@Transactional
public class WorkflowTaskServiceImpl implements WorkflowTaskService {

	@Autowired
	private RunningTaskRepository runningTaskRepository;
	@Autowired
	private RepositoryService repositoryService;
	@Autowired
	private HistoryTaskRepository historyTaskRepository;

	@Override
	public Page<TaskSearchResponse> listTodoTask(PageSearcher<TaskSearchRequest> pageSearcher) {
		return runningTaskRepository.listTodoTask(pageSearcher.getSearchCondition(), pageSearcher.getPageable());
	}

	@Override
	public Page<TaskSearchResponse> listDeptTodoTask(PageSearcher<TaskSearchRequest> pageSearcher) {
		return new PageImpl(Lists.newArrayList());
	}

	@Override
	public Page<TaskSearchResponse> listDoneTask(PageSearcher<TaskSearchRequest> pageSearcher) {
		return historyTaskRepository.listDoneTask(pageSearcher.getSearchCondition(), pageSearcher.getPageable());
	}

	@Override
	public Page<ProcessDefinitionResponse> listStartableTask(PageSearcher<TaskSearchRequest> pageSearcher) {
		return historyTaskRepository.listStartableTask(pageSearcher.getSearchCondition());
	}

	@Override
	public Long countUnreadTodoTaskCount(String account) {
		return runningTaskRepository.countUnreadTodoTaskCount(account);
	}

}
